/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * formUtama.java
 *
 * Created on Jan 9, 2012, 8:54:00 AM
 */
package aplikasi.com.gui;

import aplikasi.com.entity.Karyawan;
import aplikasi.com.implement.implemKaryawan;
import aplikasi.com.interfac.interKaryawan;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 *
 * @author Henfryandie
 */
public class formUtama extends javax.swing.JFrame {

    private Karyawan kar = new Karyawan();
    interKaryawan dataKaryawan;

    /** Creates new form formUtama */
    public formUtama() {
        initComponents();
        dataKaryawan = new implemKaryawan();
        this.setLocationRelativeTo(null);
    }

    public void kosongTxtDialogLogin() {
        txtUsername.setText(null);
        txtPasswordField.setText(null);
    }

    boolean cekLogin(String user, String pass) {
        boolean hasil = false;
        try {
            kar = dataKaryawan.getByKaryawan(user);
            if (user.equals(kar.getUserKaryawan()) && pass.equals(kar.getPassKaryawan())) {
                hasil = true;
            } else {
                hasil = false;
            }
        } catch (SQLException ex) {
            Logger.getLogger(formUtama.class.getName()).log(Level.SEVERE, null, ex);
        }
        return hasil;
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        dialogLogin = new javax.swing.JDialog();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        txtUsername = new javax.swing.JTextField();
        txtPasswordField = new javax.swing.JPasswordField();
        btnMasuk = new javax.swing.JButton();
        btnKeluar = new javax.swing.JButton();
        jDesktopPane1 = new javax.swing.JDesktopPane();
        jMenuBar1 = new javax.swing.JMenuBar();
        menuFile = new javax.swing.JMenu();
        mnuItemLogin = new javax.swing.JMenuItem();
        mnuItemKaryawan = new javax.swing.JMenuItem();
        mnuItemKeluar = new javax.swing.JMenuItem();
        mnuTransaksi = new javax.swing.JMenu();
        mnuItemPelanggan = new javax.swing.JMenuItem();
        mnuItemKomik = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();
        mnuItemSewa = new javax.swing.JMenuItem();
        mnuItemKembali = new javax.swing.JMenuItem();
        jMenuItem1 = new javax.swing.JMenuItem();
        mnuLaporan = new javax.swing.JMenu();
        mnuItemSewaKomik = new javax.swing.JMenuItem();
        mnuItemKembaliKomik = new javax.swing.JMenuItem();
        mnuItemSetoran = new javax.swing.JMenuItem();
        menuAbout = new javax.swing.JMenu();

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 18));
        jLabel1.setText("Aplikasi Rental Komik V.01");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 308, Short.MAX_VALUE)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addGap(0, 34, Short.MAX_VALUE)
                    .addComponent(jLabel1)
                    .addGap(0, 34, Short.MAX_VALUE)))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 36, Short.MAX_VALUE)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addGap(0, 7, Short.MAX_VALUE)
                    .addComponent(jLabel1)
                    .addGap(0, 7, Short.MAX_VALUE)))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel2.setText("Username");

        jLabel3.setText("Password");

        btnMasuk.setText("Masuk");
        btnMasuk.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnMasukActionPerformed(evt);
            }
        });

        btnKeluar.setText("Keluar");
        btnKeluar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnKeluarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(btnKeluar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnMasuk, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(txtPasswordField, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtUsername, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 194, Short.MAX_VALUE))
                .addContainerGap(52, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(31, 31, 31)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txtUsername, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(txtPasswordField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnMasuk)
                    .addComponent(btnKeluar))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout dialogLoginLayout = new javax.swing.GroupLayout(dialogLogin.getContentPane());
        dialogLogin.getContentPane().setLayout(dialogLoginLayout);
        dialogLoginLayout.setHorizontalGroup(
            dialogLoginLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, dialogLoginLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(dialogLoginLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        dialogLoginLayout.setVerticalGroup(
            dialogLoginLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(dialogLoginLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jDesktopPane1.setBackground(new java.awt.Color(255, 255, 255));

        menuFile.setText("File");

        mnuItemLogin.setText("Login");
        mnuItemLogin.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuItemLoginActionPerformed(evt);
            }
        });
        menuFile.add(mnuItemLogin);

        mnuItemKaryawan.setText("Karyawan");
        mnuItemKaryawan.setEnabled(false);
        mnuItemKaryawan.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuItemKaryawanActionPerformed(evt);
            }
        });
        menuFile.add(mnuItemKaryawan);

        mnuItemKeluar.setText("Keluar");
        mnuItemKeluar.setEnabled(false);
        mnuItemKeluar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuItemKeluarActionPerformed(evt);
            }
        });
        menuFile.add(mnuItemKeluar);

        jMenuBar1.add(menuFile);

        mnuTransaksi.setText("Transaksi");
        mnuTransaksi.setEnabled(false);

        mnuItemPelanggan.setText("Daftar Pelanggan");
        mnuItemPelanggan.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuItemPelangganActionPerformed(evt);
            }
        });
        mnuTransaksi.add(mnuItemPelanggan);

        mnuItemKomik.setText("Komik");
        mnuItemKomik.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuItemKomikActionPerformed(evt);
            }
        });
        mnuTransaksi.add(mnuItemKomik);

        jMenuItem2.setText("Inventaris Komik");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        mnuTransaksi.add(jMenuItem2);

        mnuItemSewa.setText("Sewa");
        mnuItemSewa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuItemSewaActionPerformed(evt);
            }
        });
        mnuTransaksi.add(mnuItemSewa);

        mnuItemKembali.setText("Kembali");
        mnuTransaksi.add(mnuItemKembali);

        jMenuItem1.setText("Cari Komik");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        mnuTransaksi.add(jMenuItem1);

        jMenuBar1.add(mnuTransaksi);

        mnuLaporan.setText("Laporan");
        mnuLaporan.setEnabled(false);

        mnuItemSewaKomik.setText("Sewa Komik");
        mnuItemSewaKomik.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuItemSewaKomikActionPerformed(evt);
            }
        });
        mnuLaporan.add(mnuItemSewaKomik);

        mnuItemKembaliKomik.setText("Kembali Komik");
        mnuItemKembaliKomik.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuItemKembaliKomikActionPerformed(evt);
            }
        });
        mnuLaporan.add(mnuItemKembaliKomik);

        mnuItemSetoran.setText("Setoran");
        mnuItemSetoran.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuItemSetoranActionPerformed(evt);
            }
        });
        mnuLaporan.add(mnuItemSetoran);

        jMenuBar1.add(mnuLaporan);

        menuAbout.setText("About");
        jMenuBar1.add(menuAbout);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jDesktopPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 740, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jDesktopPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 407, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void mnuItemKeluarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuItemKeluarActionPerformed
        dialogLogin.setVisible(true);
        mnuItemKaryawan.setVisible(true);
        mnuItemKaryawan.setEnabled(false);
        mnuLaporan.setEnabled(false);
        mnuTransaksi.setEnabled(false);
        mnuItemKeluar.setEnabled(false);
        mnuItemLogin.setEnabled(true);
        this.setTitle("");
    }//GEN-LAST:event_mnuItemKeluarActionPerformed

    private void mnuItemLoginActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuItemLoginActionPerformed
        dialogLogin.setSize(350, 230);
        dialogLogin.setLocationRelativeTo(null);
        dialogLogin.setVisible(true);
    }//GEN-LAST:event_mnuItemLoginActionPerformed

    private void mnuItemKaryawanActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuItemKaryawanActionPerformed
        // TODO add your handling code here:
        formTambahKaryawan tambahKary = new formTambahKaryawan();
        jDesktopPane1.add(tambahKary);
        tambahKary.setVisible(true);
    }//GEN-LAST:event_mnuItemKaryawanActionPerformed

    private void mnuItemSewaKomikActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuItemSewaKomikActionPerformed
        // TODO add your handling code here:
        formLaporanTransaksiSewa transSewa = new formLaporanTransaksiSewa();
        jDesktopPane1.add(transSewa);
        transSewa.setVisible(true);
    }//GEN-LAST:event_mnuItemSewaKomikActionPerformed

    private void mnuItemKembaliKomikActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuItemKembaliKomikActionPerformed
        // TODO add your handling code here:
        formLaporanTransaksiKembali transKem = new formLaporanTransaksiKembali();
        jDesktopPane1.add(transKem);
        transKem.setVisible(true);
    }//GEN-LAST:event_mnuItemKembaliKomikActionPerformed

    private void mnuItemSetoranActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuItemSetoranActionPerformed
        // TODO add your handling code here:
        formSetoran set = new formSetoran();
        jDesktopPane1.add(set);
        set.setVisible(true);
    }//GEN-LAST:event_mnuItemSetoranActionPerformed

    private void btnMasukActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnMasukActionPerformed
        if (cekLogin(txtUsername.getText(), txtPasswordField.getText()) && kar.getAkses().equals("Karyawan")) {
            mnuItemKaryawan.setVisible(false);
            mnuItemSetoran.setVisible(true);
            mnuTransaksi.setEnabled(true);
            mnuItemKeluar.setEnabled(true);
            mnuLaporan.setEnabled(true);
            mnuItemSetoran.setVisible(false);
            mnuItemLogin.setEnabled(false);
            this.setTitle("Nama " + kar.getAkses() + " : " + kar.getNamaKaryawan() + "  --  APLIKASI RENTAL KOMIK");
            JOptionPane.showMessageDialog(this, "Selamat Datang " + txtUsername.getText());
            this.kosongTxtDialogLogin();
            dialogLogin.dispose();
        } else if (cekLogin(txtUsername.getText(), txtPasswordField.getText()) && kar.getAkses().equals("Admin")) {
            mnuItemKaryawan.setEnabled(true);
            mnuTransaksi.setEnabled(true);
            mnuLaporan.setEnabled(true);
            mnuItemKeluar.setEnabled(true);
            mnuItemLogin.setEnabled(false);
            mnuItemSetoran.setEnabled(true);
            this.setTitle("Nama " + kar.getAkses() + " : " + kar.getNamaKaryawan() + "  --  APLIKASI RENTAL KOMIK");
            JOptionPane.showMessageDialog(this, "Selamat Datang " + txtUsername.getText());
            this.kosongTxtDialogLogin();
            dialogLogin.dispose();
        } else {
            JOptionPane.showMessageDialog(this, "Maaf, Username dan password anda tidak sesuai..!", "Kesalahan", JOptionPane.ERROR_MESSAGE);
            this.kosongTxtDialogLogin();
        }
    }//GEN-LAST:event_btnMasukActionPerformed

    private void mnuItemKomikActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuItemKomikActionPerformed
        fromTambahKomik nekawa = new fromTambahKomik();
        jDesktopPane1.add(nekawa);
        nekawa.setVisible(true);
    }//GEN-LAST:event_mnuItemKomikActionPerformed

    private void mnuItemPelangganActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuItemPelangganActionPerformed
        formTambahPelanggan nekawa = new formTambahPelanggan();
        jDesktopPane1.add(nekawa);
        nekawa.setVisible(true);
    }//GEN-LAST:event_mnuItemPelangganActionPerformed

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        // TODO add your handling code here:
        formCariKomik nekawa = new formCariKomik();
        jDesktopPane1.add(nekawa);
        nekawa.setVisible(true);
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void mnuItemSewaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuItemSewaActionPerformed
        // TODO add your handling code here:
        formSewa nekawa = null;
        try {
            nekawa = new formSewa();
        } catch (SQLException ex) {
            Logger.getLogger(formUtama.class.getName()).log(Level.SEVERE, null, ex);
        }
        jDesktopPane1.add(nekawa);
        nekawa.setVisible(true);
    }//GEN-LAST:event_mnuItemSewaActionPerformed

    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
        // TODO add your handling code here:
        formTambahInventaris inventaris = new formTambahInventaris();
        jDesktopPane1.add(inventaris);
        inventaris.setVisible(true);

    }//GEN-LAST:event_jMenuItem2ActionPerformed

    private void btnKeluarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnKeluarActionPerformed
        System.exit(0);
    }//GEN-LAST:event_btnKeluarActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {

        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new formUtama().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnKeluar;
    private javax.swing.JButton btnMasuk;
    private javax.swing.JDialog dialogLogin;
    private javax.swing.JDesktopPane jDesktopPane1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JMenu menuAbout;
    private javax.swing.JMenu menuFile;
    private javax.swing.JMenuItem mnuItemKaryawan;
    private javax.swing.JMenuItem mnuItemKeluar;
    private javax.swing.JMenuItem mnuItemKembali;
    private javax.swing.JMenuItem mnuItemKembaliKomik;
    private javax.swing.JMenuItem mnuItemKomik;
    private javax.swing.JMenuItem mnuItemLogin;
    private javax.swing.JMenuItem mnuItemPelanggan;
    private javax.swing.JMenuItem mnuItemSetoran;
    private javax.swing.JMenuItem mnuItemSewa;
    private javax.swing.JMenuItem mnuItemSewaKomik;
    private javax.swing.JMenu mnuLaporan;
    private javax.swing.JMenu mnuTransaksi;
    private javax.swing.JPasswordField txtPasswordField;
    private javax.swing.JTextField txtUsername;
    // End of variables declaration//GEN-END:variables
}
